package com.ly.base.jdbc.utils;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @Classname JDBCUtils
 * @Description TODO
 * @Date 2020/11/2 16:00
 * @Author 冷心影翼
 */
public class JDBCUtils {

	public static Connection getConnection() {
		try{
			InputStream resourceAsStream = JDBCUtils.class.getClassLoader().getResourceAsStream("mysql.properties");
			Properties properties = new Properties();
			properties.load(resourceAsStream);
			return DriverManager.getConnection(properties.getProperty("url"),properties);
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}

	public static void closeConnection(Connection con) {
		try{
			if(con!=null) {
				con.close();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
